﻿using System.Diagnostics.Contracts;
using System.Windows;
using System.Windows.Controls;

namespace OpenLS.Spreadsheet.UI.Internals
{
    class CommentTemplateSelector: DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            Contract.Ensures(Contract.Result<DataTemplate>() != null);
            Contract.Assert(item is Comment);
            FrameworkElement element = (FrameworkElement) container;
            DataTemplate result = (DataTemplate) element.TryFindResource(new DataTemplateKey(typeof (Comment)));
            if (result != null)
                return result;
            result = (DataTemplate) CommentResources.Instance[new DataTemplateKey(typeof (Comment))];
            return result;
        }
    }
}